package com.hl.yyx.common.constants;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum MatchMode {
    LIKE("like"),
    EQUAL("eq"),
    NOT_EQUAL("ne"),
    GREATER_THAN("gt"),
    GREATER_THAN_OR_EQUAL("ge"),
    LESS_THAN("lt"),
    LESS_THAN_OR_EQUAL("le"),
    IN("in"),
    NOT_IN("notIn"),
    BETWEEN("between"),
    IS_NULL("isNull"),
    IS_NOT_NULL("isNotNull");

    private final String value;

    MatchMode(String value) {
        this.value = value;
    }

    @JsonValue  // 序列化时使用这个值
    public String getValue() {
        return value;
    }

    @JsonCreator  // 反序列化时使用这个方法
    public static MatchMode fromValue(String value) {
        for (MatchMode mode : values()) {
            if (mode.value.equalsIgnoreCase(value)) {
                return mode;
            }
        }
        throw new IllegalArgumentException("Unknown match mode: " + value);
    }
}
